﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CashFund.ascx.cs" Inherits="ERP.Modules.CashFund" %>
<script type="text/javascript">
    var indMoneyCashFund = function (v) {
        v = (Math.round((v - 0) * 100)) / 100;
        v = (v == Math.floor(v)) ? v + ".00" : ((v * 10 == Math.floor(v * 10)) ? v + "0" : v);
        v = String(v);
        var ps = v.split('.'),
            whole = ps[0],
            sub = ps[1] ? '.' + ps[1] : '.00',
            r = /(\d+)(\d{3})/;
        while (r.test(whole)) {
            whole = whole.replace(r, '$1' + ',' + '$2');
        }
        v = whole;

        return v;
    };
    var NumCheckCashFund = function () {
        var y = window.App.txtAmount_Original.getValue();
        var k = window.App.txtAmount_Current.getValue();
        window.App.txtAmount_Original.setValue(FormatNumber(y));
        window.App.txtAmount_Current.setValue(FormatNumber(y));
    };
</script>
<%-------------------------------%>
<ext:Hidden ID="FormatTypeCashFund" runat="server" />
<ext:Panel runat="server" Layout="Fit" Border="False" ID="PanelCashFund">
    <Content>
        <%--------------GridCashFund-----------------%>
        <ext:GridPanel
            ID="grCashFund"
            Cls="grid-double"
            runat="server"
            EnableColumnMove="true"
            Border="False">
            <Store>
                <%-------------StoreCashFund-----------------%>
                <ext:Store
                    ID="StoreCashFund"
                    runat="server"
                    OnReadData="StoreCashFund_RefreshData"
                    PageSize="20">
                    <Model>
                        <ext:Model runat="server" IDProperty="ID_CashFund" GroupField="Bank_Account_Name">
                            <Fields>
                                <ext:ModelField Name="ID_CashFund" Type="Int" />
                                <ext:ModelField Name="Bank_Account_ID" Type="String" />
                                <ext:ModelField Name="Cash_Fund_Code" Type="String" />
                                <ext:ModelField Name="Cash_Fund_Name" Type="String" />
                                <ext:ModelField Name="Amount_Original" Type="Float" />
                                <ext:ModelField Name="Amount_Current" Type="Float" />
                                <ext:ModelField Name="Amount_Profit" Type="Float" />
                                <ext:ModelField Name="Bank_Name" Type="String" />
                                <ext:ModelField Name="Bank_Account_Name" Type="String" />
                            </Fields>
                        </ext:Model>
                    </Model>
                </ext:Store>
            </Store>
            <ColumnModel runat="server">
                <Columns>
                    <ext:RowNumbererColumn runat="server" Width="30" Align="Center" />
                    <ext:Column runat="server" Text="Mã Code" Width="150" DataIndex="Cash_Fund_Code"></ext:Column>
                    <ext:Column runat="server" Text="Tên tài khoản" Width="200" DataIndex="Bank_Account_Name"></ext:Column>
                    <ext:Column runat="server" Text="Tên quỹ" Width="200" DataIndex="Cash_Fund_Name"></ext:Column>
                    <ext:NumberColumn runat="server" Text="Số dư tiền mặt ban đầu" Width="200" DataIndex="Amount_Original" Format="0,00" Align="Center"/>
                    <ext:NumberColumn runat="server" Text="Số dư tiền mặt hiện tại" Flex="1" DataIndex="Amount_Current" Format="0,00" Align="Center"/>
                </Columns>
            </ColumnModel>
            <Features>
                <ext:Grouping
                    runat="server"
                    HideGroupedHeader="true"
                    GroupByText="Xem theo phân nhóm"
                    ShowGroupsText="Phân nhóm"
                    GroupHeaderTplString="{name} ({rows.length} danh mục con {[values.rows.length > 1 ? '' : '']})"
                    StartCollapsed="True" />
            </Features>
            <DirectEvents>
                <ItemDblClick OnEvent="CashFundDblClick">
                    <ExtraParams>
                        <ext:Parameter Name="ID_CashFund" Value="record.data.ID_CashFund" Mode="Raw" />
                    </ExtraParams>
                    <EventMask ShowMask="true" Msg="Đang tải..." />
                </ItemDblClick>
            </DirectEvents>
            <SelectionModel>
                <ext:CheckboxSelectionModel runat="server" Mode="Multi">
                    <Listeners>
                       <SelectionChange Handler="
                            if (selected.length == 0) {
                                #{btnEdit}.disable();
                                #{btnDel}.disable();
                                #{btnExport}.disable();
                            } else {
                                #{btnEdit}.enable();
                                #{btnDel}.enable();
                                #{btnExport}.enable();
                            }" />
                   </Listeners>
                </ext:CheckboxSelectionModel>
            </SelectionModel>
            <BottomBar>
                <ext:Toolbar runat="server">
                    <Items>
                        <ext:ToolbarFill runat="server" />
                        <ext:Label runat="server" Text="Tổng số dư tiền mặt ban đầu :" Cls="total-field"></ext:Label>
                        <ext:Label ID="lbToal_Amount_Original" runat="server" Text="200,000,000" Cls="total-field-num"></ext:Label>
                        <ext:ToolbarSeparator />
                        <ext:Label runat="server" Text="Tổng số dư tiền mặt hiện tại :" Cls="total-field"></ext:Label>
                        <ext:Label ID="lbTotal_Amount_Current" runat="server" Text="200,000,000" Cls="total-field-num"></ext:Label>
                    </Items>
                </ext:Toolbar>
            </BottomBar>
            <DockedItems>
                <ext:Toolbar ID="ToolbarTopMain" runat="server" Dock="Top">
                    <Items>
                        <ext:Button ID="btnAddNew" runat="server" Text="Thêm mới" Icon="ApplicationAdd">
                            <DirectEvents>
                                <Click OnEvent="btnAddNew_Click">
                                    <EventMask ShowMask="true" Msg="Đang tải..." />
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                        <ext:ToolbarSeparator />
                        <ext:Button ID="btnEdit" runat="server" Text="Sửa" Icon="ApplicationEdit">
                            <DirectEvents>
                                <Click OnEvent="btnEdit_Click">
                                    <EventMask ShowMask="true" Msg="Đang tải..." />
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                        <ext:ToolbarSeparator />
                        <ext:Button ID="btnDel" runat="server" Text="Xoá" Icon="ApplicationDelete">
                            <DirectEvents>
                                <Click OnEvent="btnDel_Click">
                                    <EventMask ShowMask="true" Msg="Đang tải..." />
                                    <ExtraParams>
                                        <ext:Parameter Name="name" Value="btnDel"></ext:Parameter>
                                    </ExtraParams>
                                    <Confirmation ConfirmRequest="true"
                                        Title="Thông Báo" Message="Bạn có muốn xoá mẫu tin này không ?">
                                    </Confirmation>
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                        <ext:ToolbarSeparator />
                        <ext:Button ID="btnExport" runat="server" Text="Xuất tập tin" Icon="Printer">
                            <Menu>
                                <ext:Menu ID="MenuMain" runat="server">
                                    <Items>
                                        <ext:MenuItem ID="MenuItemExportXML" runat="server" Text="XML" Icon="PageCode">
                                            <Listeners>
                                                <Click Handler="submitValue(#{grCashFund}, #{FormatTypeCashFund}, 'xml');" />
                                            </Listeners>
                                        </ext:MenuItem>
                                    </Items>
                                </ext:Menu>
                            </Menu>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
                <ext:Toolbar ID="ToolbarPagging" runat="server" Dock="Bottom" AnchorHorizontal="100%">
                    <Items>
                        <ext:TriggerField ID="txtSearch" runat="server" Width="200" EnableKeyEvents="true" MarginSpec="0 8 0 0">
                            <Triggers>
                                <ext:FieldTrigger Icon="Search" />
                            </Triggers>
                            <DirectEvents>
                                <TriggerClick OnEvent="Search_Event"></TriggerClick>
                                <SpecialKey OnEvent="Search_Event" Before="return e.getKey() == Ext.EventObject.ENTER;">
                                     <EventMask ShowMask="true" Msg="Đang tải..." />
                                </SpecialKey>
                            </DirectEvents>
                        </ext:TriggerField>
                        <ext:SelectBox
                            ID="SelectBoxCashFund"
                            runat="server"
                            Cls="x-select-box"
                            DisplayField="Bank_Account_Name"
                            ValueField="Bank_Account_ID"
                            MarginSpec="0 8 0 0"
                            EmptyText="Chọn tên tài khoản">
                            <Store>
                                <ext:Store ID="StoreCashFundSelect" runat="server">
                                    <Model>
                                        <ext:Model runat="server">
                                            <Fields>
                                                <ext:ModelField Name="Bank_Account_Name" />
                                                <ext:ModelField Name="Bank_Account_ID" />
                                            </Fields>
                                        </ext:Model>
                                    </Model>
                                </ext:Store>
                            </Store>
                            <DirectEvents>
                                <Select OnEvent="SelectBoxCashFund_Change">
                                    <EventMask ShowMask="true" Msg="Đang tải..."></EventMask>
                                </Select>
                            </DirectEvents>
                        </ext:SelectBox>
                        <ext:PagingToolbar ID="PagingToolbarCashFund" runat="server" StoreID="StoreCashFund" BeforePageText="Trang" AfterPageText="của {0}" LastText="Cuối" NextText="Kế tiếp" PrevText="Trở lại" FirstText="Đầu" RefreshText="Làm tươi" DisplayInfo="true" DisplayMsg="Trang {0} - {1} của {2}" />
                    </Items>
                </ext:Toolbar>
            </DockedItems>
        </ext:GridPanel>
    </Content>
</ext:Panel>
<ext:Panel runat="server">
    <Content>
        <%-----------WindowsCashFund-----------------%>
        <ext:Window ID="WindowsCashFund" runat="server"
            Title="Các khoản quỹ"
            DefaultAnchor="100%"
            Width="379px"
            Height="246px"
            Hidden="true"
            AutoScroll="False"
            Maximizable="False"
            Minimizable="False"
            AutoDataBind="True"
            Region="Center"
            Resizable="False"
            Modal="True"
            HideMode="Offsets"
            Border="False"
            Padding="5"
            DefaultButton="btnSavePopUp">
            <Items>
                <ext:Toolbar runat="server">
                    <Items>
                        <ext:Button runat="server" Text="Lưu lại" Icon="Disk" ID="btnSavePopUp">
                            <DirectEvents>
                                <Click OnEvent="btnSavePopUp_Click" Before="return #{FormPanelCashFund}.isValid();">
                                    <EventMask ShowMask="true" Msg="Đang tải..." />
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                        <ext:Button runat="server" Text="Huỷ bỏ" Icon="Decline" ID="btnCancelPopUp">
                            <DirectEvents>
                                <Click OnEvent="btnCancelPopUp_Click">
                                    <EventMask ShowMask="true" Msg="Đang tải..." />
                                </Click>
                            </DirectEvents>
                        </ext:Button>
                        <ext:TextField ID="txtCashFund_ID" runat="server" FieldLabel="ID" LabelAlign="Right" Hidden="true" />
                    </Items>
                </ext:Toolbar>
                <ext:FormPanel runat="server"
                    ID="FormPanelCashFund"
                    AutoHeight="true"
                    BodyPadding="10"
                    Frame="true"
                    DefaultAnchor="100%">
                    <Items>
                        <ext:TextField ID="txtCashFund_Name_Code" runat="server" FieldLabel="Mã code" AnchorHorizontal="100%" AllowBlank="false" />
                        <ext:TextField ID="txtCashFund_Name" runat="server" FieldLabel="Tên quỹ" AnchorHorizontal="100%" AllowBlank="false" />
                        <ext:FieldContainer runat="server" Layout="HBox">
                            <Items>
                                <ext:ComboBox
                                    ID="cbCashFundMethod"
                                    runat="server"
                                    QueryMode="Local"
                                    SelectOnFocus="true"
                                    ForceSelection="True"
                                    FieldLabel="Thuộc khoản" AnchorHorizontal="100%" AllowBlank="false"
                                    DisplayField="Bank_Account_Name"
                                    ValueField="Bank_Account_ID"
                                    EmptyText="Vui lòng chọn thuộc khoản"
                                    ContextMenuID="ctCashFundMethod" MarginSpec="0 5 0 0" Width="310">
                                    <Store>
                                        <ext:Store runat="server" ID="CashFundMethodStore" AutoLoad="true" OnReadData="ReloadComboBox">
                                            <Model>
                                                <ext:Model runat="server" IDProperty="Bank_Account_ID">
                                                    <Fields>
                                                        <ext:ModelField Name="Bank_Account_Name" Type="String" />
                                                    </Fields>
                                                </ext:Model>
                                            </Model>
                                        </ext:Store>
                                    </Store>
                                </ext:ComboBox>
                                <ext:Button runat="server" Icon="Add">
                                    <Listeners>
                                        <Click Handler="#{WindowsBank_Account}.show();"></Click>
                                    </Listeners>
                                    <ToolTips>
                                        <ext:ToolTip runat="server" Html="Thêm mới loại tài khoản" />
                                    </ToolTips>
                                </ext:Button>
                            </Items>
                        </ext:FieldContainer>
                        <ext:TextField ID="txtAmount_Original" runat="server" FieldStyle="text-align: right;" FieldLabel="Số dư tiền mặt ban đầu" AnchorHorizontal="100%" ClientIDMode="Static" AllowBlank="True" Text="0" MaskRe="/[0-9\.]/" Margins="0 10 8 0">
                            <Listeners>
                                <Change Fn="NumCheckCashFund" />
                            </Listeners>
                        </ext:TextField>
                        <ext:TextField ID="txtAmount_Current" ReadOnly="True" runat="server" FieldStyle="text-align: right;" FieldLabel="Số dư tiền mặt hiện tại" AnchorHorizontal="100%" ClientIDMode="Static" AllowBlank="True" Text="0" MaskRe="/[0-9\.]/" Margins="0 10 8 0">
                            <Listeners>
                               <Change Handler="this.setValue(Ext.util.Format.number(newValue.replace(/[\,\.]/g, ''), '0.000/i').replace(/[.]/g, ','));" />
                            </Listeners>
                        </ext:TextField>
                    </Items>
                </ext:FormPanel>
            </Items>
        </ext:Window>
        <ext:Menu runat="server" ID="ctCashFundMethod">
            <Items>
                <ext:Button runat="server" Text="Tải lại" Icon="DatabaseRefresh" Flat="True">
                    <Listeners>
                        <Click Handler="#{cbCashFundMethod}.clearValue(); #{CashFundMethodStore}.reload(); #{ctCashFundMethod}.hide();"></Click>
                    </Listeners>
                </ext:Button>
            </Items>
        </ext:Menu>
    </Content>
</ext:Panel>